<?php

namespace app\modules\admin\controllers;

use yii\web\Controller;
use app\modules\admin\models\Tbllogin_form;
use app\modules\admin\models\Tbluser;

class DefaultController extends HoutaiController
{

	// PUBLIC $layout =false;
	  
    public function actionIndex()
    {
    	
    	
    	

    	
    	$model = new Tbllogin_form();
         
       if ($model->load( \Yii::$app->request->post())) {
        if ($model->validate()) {
            // form inputs are valid, do something here

            $request =	\Yii::$app->request;
            
           
        	
        	//echo "username='".$_POST['Tbllogin_form']['username']."' and password = '".$_POST['Tbllogin_form']['password']."'";
        	
        	$user = Tbluser::find()->where(
        			"username='".$_POST['Tbllogin_form']['username']."' and password = '".md5($_POST['Tbllogin_form']['password'])."'"
        			)->asArray()->one();
        	
        	//print_R($user);
             if($user)
             {
             	
             	\Yii::$app->session['user_info'] = $user;
             	
             	
             	print_r(\Yii::$app->session['user_info']);
             	
             	echo "可以登陆了";
                exit; 	
             }
            
        	
        }
       }
       
       return $this->render('user_login', [
        'model' => $model,
       ]);
    
    }
    
}
